﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace BlueLotus7.ArchiveSystem.Common
{
    [DataContract]
    public class MonitorProcessRuleTarget
    {
        [DataMember]
        public bool ApplyToAll
        {
            get;
            set;
        }

        [DataMember]
        public List<DomainScopeUser> TargetList
        {
            get;
            set;
        }

        public bool IsMatch(string identity)
        {
            bool result = false;

            if (!string.IsNullOrWhiteSpace(identity))
            {
                result = ApplyToAll;

                if (!result && this.TargetList != null)
                {
                    foreach (var t in this.TargetList)
                    {
                        if (t.ThirdPartyIdentity.Equals(identity, StringComparison.InvariantCultureIgnoreCase))
                        {
                            result = true;
                            break;
                        }
                    }
                }
            }

            return result;
        }

        public bool IsMatch(Guid identity)
        {
            bool result = ApplyToAll;

            if (!result && this.TargetList != null)
            {
                foreach (var t in this.TargetList)
                {
                    if (t.Key == identity)
                    {
                        result = true;
                        break;
                    }
                }
            }

            return result;
        }

    }
}
